//
//  String+Extension.swift
//  VISUAL
//
//  Created by 刘森 on 2019/12/5.
//  Copyright © 2019 admin. All rights reserved.
//

import Foundation


extension String {
    func intValue() -> Int? {
        return (self as NSString).integerValue
    }
    func doubleValue() -> Double? {
        return (self as NSString).doubleValue
    }
    func floatValue() -> Float? {
        return (self as NSString).floatValue
    }
    func isIntValue() -> Bool {
        let scan: Scanner = Scanner(string: self)
        var val:Int = 0
        return scan.scanInt(&val) && scan.isAtEnd
    }
    func isNumberAndLetterValue() -> Bool {
        let reg = "^[a-zA-Z0-9]+$"
        let pre = NSPredicate(format: "SELF MATCHES %@", reg)
        if pre.evaluate(with: self) {
            return true
        }else{
            return false
        }
    }
    
    func base64Value() -> String? {
        let utf8EncodeData = self.data(using: String.Encoding.utf8, allowLossyConversion: true)
        let base64String = utf8EncodeData?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: UInt(0)))
        return base64String
    }
    
    
}
